#!/usr/bin/env python2.6

import Stemmer

import ebook
import index

def ebookTest():
    #ebook = ebook('./books/testbook.epub')
    path = './books'
    files = ebook.getListOfEBookFiles(path)
    cnt = 0
    for file in files:
        cnt += 1
        print(cnt, file)
        book = ebook.ebook(file)
        print(book.title)
        print(book.creator)
        print()

def stemmerTest():
    stemmer = Stemmer.Stemmer('english')
    s = 'functionally'
    print s
    ss = stemmer.stemWord(s)
    print ss

def main():
    print 'Building index...'
    idx = index.buildInvIndex('./books')
    print 'Saving index to file...'
    index.storeIndexToFile(idx, 'books.idx')
    print 'Loading index from file...'
    idx = index.loadIndexFromFile('books.idx')

    print '\nSearching...'
    print ''
    books = idx.search('time')
    for book in books:
        print book.title
        print book.creator
        print book.fileName
        print ''

if __name__ == '__main__':
    print('elib v0.1')
    main()
    #ebookTest()

